import {Api} from "./index.js"
import Request from "@/utils/request.js"
import Message from "@/utils/message.js"

export const LoadRecommendVideo = async () => {
    let result = await Request({
        url: Api.loadRecommendVideo,
    })
    return result
}

export const LoadVideo = async (data) => {
    let result = await Request({
        url: Api.loadVideo,
        params: {
            ...data
        }
    })
    return result
}

export const GetVideoInfo = async (videoId) => {
    let result = await Request({
        url: Api.getVideoInfo,
        params: {
            videoId: videoId
        }
    })
    return result
}

export const GetLoadDanmu = async (videoId) => {
    let result = await Request({
        url: Api.LoadDanmu,
        params: {
            videoId
        }
    })
    return result
}

export const GetloadVideoPList = async (videoId) => {
    let result = await Request({
        url: Api.loadVideoPList,
        params: {
            videoId: videoId
        }
    })
    return result
}

export const PostLoadDanmu = async (videoId,danmu,uuid) => {
    let result = await Request({
        url: Api.addDanmu,
        params: {
            videoId: videoId,
            bnr: danmu.text,
            mode: danmu.mode,
            color: danmu.color,
            time : danmu.time,
            userId: uuid
        }
    })
    return result
}

export const AddWatch = async (videoId,userCookie) => {
    let result = await Request({
        url: Api.addWatch,
        params: {
            videoId,
            userCookie
        }
    })
    return result
}

export const LoadWatch = async (videoId) => {
    let result = await Request({
        url: Api.loadWatch,
        params: {
            videoId
        }
    })
    return result
}

export const LoadVideoComment = async (videoId,pageNo,orderType) => {
    let result = await Request({
        url: Api.loadVideoComment,
        params: {
            videoId,
            pageNo,
            orderType
        }
    })
    return result.data
}

export const AddComment = async (formData) => {
    console.log(formData)
    let result = await Request({
        url: Api.addComment,
        params: {
            content:formData.content,
            pCommentId:formData.replyCommentId?formData.replyCommentId:0,
            userId:formData.userId,
            videoId:formData.videoId,
            replyUserId:formData.replyUserId?formData.replyUserId:0,
            imgPath:formData.imgPath
        }
    })
    return result
}

export const TopComment = async (commentId) => {
    let result = await Request({
        url: Api.topComment,
        params: {
            commentId
        }
    })
    return result
}
export const CancelTopComment = async (commentId,pcommentId) => {
    let result = await Request({
        url: Api.cancelTopComment,
        params: {
            commentId,
            pcommentId
        }
    })
    return result
}
export const DeleteComment = async (commentId,pcommentId) => {
    let result = await Request({
        url: Api.deleteComment,
        params: {
            commentId,
            pcommentId
        }
    })
    return result
}

export const Upload_Comment = async (file) => {
    let result = await Request({
        url: Api.upload_comment,
        params: {
            file
        }
    })
    return result
}